module Resistor
    ###
    # collection of ActionController methods for dealing with FileColumn uploads
    #
    module ActionController

        module UploadQueue
            def queue_upload(upload)
                session[:upload_queue] = [] if session[:upload_queue].nil?

                # cache upload filename into session.
                session[:upload_queue] << {:model => upload[:record].class.to_s, :attribute => upload[:attribute], :id => upload[:record].id, :filename => upload[:filename]}

                LOG.info('CCA::ActionController queue_upload -- added upload to queue')
                LOG.info('current queue: ' + session[:upload_queue].to_yaml)
            end

            def find_upload_from_queue
                (!session[:upload_queue].nil?) ? session[:upload_queue].delete(session[:upload_queue].find {|f| f[:model] == params["model"] && f[:filename] == params["file"].original_filename}) : nil
            end
        end
    end
end
##
# extend ActionController::Base
#
ActionController::Base.send(:include, Resistor::ActionController::UploadQueue)